
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<html>
<head>
    <title>Title</title>
    <jsp:include page="../../common/css_js.jsp" />
</head>
<body>
<div class="container">
<%--    添加新订单，配合insert插入到数据库--%>
    <h3>订单详情</h3><a class="btn btn-success" href="${pageContext.request.contextPath}/goods/getAllByPage">返回商品页面</a>
<%--    <button class="btn btn-success btn-sm" onclick="addOneOrder()">添加订单</button>--%>
    <table class="table">
        <thead>
        <tr>
            <th>订单序号</th>
<%--            <th>用户号</th>--%>
            <th>用户名</th>
            <th>联系电话</th>
<%--            <th>商品号</th>--%>
            <th>商品名</th>
            <th>订单号</th>
            <th>销售时间</th>
            <th>单价</th>
            <th>数量</th>
<%--            <th>订单总价</th>--%>
            <th>收货地址</th>
            <th>订单状态</th>
<%--            <th>状态更新</th>--%>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${Detail}" var="one">
            <tr id="b_${one.orderId}">
<%--                <td class="detailId">${one.orderId}</td>--%>
                <td class="orderId">${one.orderId}</td>
                <td class="userName">${one.userName}</td>
                <td class="phone">${one.phone}</td>
<%--                <td class="orderPrice">${one.goodsId}</td>--%>
                <td class="goodsName">${one.goodsName}</td>
                <td class="orderNum">${one.orderNum}</td>
                <td class="orderTime">${one.orderTime}</td>
                <td class="price">${one.price}</td>
                <td class="number">${one.number}</td>
<%--                <td class="saleNum">${one.totalPrice}</td>--%>
                <td class="address">${one.address}</td>
                <td class="status">${one.status}</td>
<%--                <td class="dealedStatus">未处理</td>--%>
<%--                <td><a href="#" class="btn btn-sm btn-success">处理订单</a></td>--%>
                <td><a class="btn btn-info btn-sm" href="javascript:"  onclick="dealOrder(${one.orderId})">处理订单</a></td>
            </tr>

        </c:forEach>

        </tbody>
    </table>


    <%--    处理订单的模态框--%>
    <div class="modal fade" id="dealModal">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header">
                    <h5 class="modal-title">处理订单</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">
                    <form id="editForm" action="/manager/updateOrder" method="post" onsubmit="return false;">
                        <div class="form-group">
                            <label>订单序号</label>
                            <input type="text" name="orderId" id="orderId"  class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>用户名</label>
                            <input type="text" name="userName" id="userName" class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>联系电话</label>
                            <input type="text" name="phone" id="phone" class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>商品名</label>
                            <input type="text" name="goodsName" id="goodsName" class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>订单号</label>
                            <input type="text" name="orderNum" id="orderNum" class="form-control" readonly>
                        </div>
                        <div class="form-group">
                            <label>订单状态</label>
                            <input type="text" name="status" id="status" class="form-control">
                        </div>
<%--                        <div class="form-group">--%>
<%--                            <label>状态变更</label>--%>
<%--                            <input type="text" name="dealedStatus" id="dealedStatus" class="form-control">--%>
<%--                        </div>--%>
                    </form>
                </div>

                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" onclick="doDeal()">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    function dealOrder(orderId) {
        $("#dealModal").modal("show");
        $("#orderId").val($("#b_" + orderId + " .orderId").text());
        $("#userName").val($("#b_" + orderId + " .userName").text());
        $("#phone").val($("#b_" + orderId + " .phone").text());
        $("#goodsName").val($("#b_" + orderId + " .goodsName").text());
        $("#orderNum").val($("#b_" + orderId + " .orderNum").text());
        $("#status").val($("#b_" + orderId + " .status").text());
    }

    function doDeal() {
        $.ajax({
            url:"updateOrder",
            method:"post",
            data:{
                // orderId:$("#orderId").val(),
                orderId:$("#orderId").val(),
                userName:$("#userName").val(),
                phone:$("#phone").val(),
                goodsId:$("#goodsId").val(),
                status:$("#status").val()
                // statusName:$("#statusName").val(),
                // dealedStatus:$("#dealedStatus").val()
            },
            success:function (data) {
                console.log(data);
                if(data != null) {
                    alert("修改成功");
                    location.reload();
                }
                else alert("修改失败");
            },
            error:function (e) {
                console.log(e);
                console.log("通讯错误");
            }
        });

    }


</script>
</body>
</html>
